package org.crl.blogsystem.repository;

import jakarta.transaction.Transactional;
import org.crl.blogsystem.entity.Like;
import org.crl.blogsystem.entity.LikeId;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface LikeRepository extends CrudRepository<Like, LikeId> {
    boolean existsByUser_IdAndBlog_Id(Long userId, Long blogId);

    @Transactional
    @Modifying
    @Query("DELETE FROM Like l WHERE l.user.id = :userId AND l.blog.id = :blogId")
    void deleteByUserIdAndBlogId(@Param("userId") Long userId, @Param("blogId") Long blogId);
}
